package primetest.impl.service;

import java.io.IOException;
import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;

import primetest.dto.ChargeDto;
import primetest.impl.dao.ChargeDao;
import primetest.impl.dao.Transaction;
import primetest.impl.service.ChargeService;

public class ChargeService implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -2425578018416960291L;
	/**
	 *
	 */

	private Transaction transaction;
	private ChargeDao chargeDao;

	@Inject
	public ChargeService(Transaction transaction,ChargeDao chargeDao){
		this.transaction = transaction;
		this.chargeDao = chargeDao;
	}

	public List<ChargeDto> getChargeList() throws IOException {
		try{
			transaction.begin();
			List<ChargeDto> chargeList = chargeDao.getAllList(transaction);
			//transaction.commit();
			return chargeList;
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}



	public void addCharge(ChargeDto chargeDto) throws IOException {
		try{
			transaction.begin();
			chargeDao.addCharge(transaction, chargeDto);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}


	public void updateCharge(ChargeDto chargeDto) throws IOException {
		try{
			transaction.begin();
			chargeDao.updateCharge(transaction, chargeDto);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}


	public void deleteCharge(String chargeSeq) throws IOException {
		try{
			transaction.begin();
			chargeDao.deleteCharge(transaction, chargeSeq);
			transaction.commit();
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}

	public ChargeDto findCharge(String chargeSeq) throws IOException {
		try{
			transaction.begin();
			return chargeDao.findCharge(transaction, chargeSeq);
		}catch(IOException e){
			transaction.rollback();
			throw e;
		}
	}
}
